<?php

namespace app\api\service\ai;

use app\api\model\AiCompletionsDetail;
use think\Env;

class Nami extends Base
{

    protected $type = 'nami';

    protected $completionsUrl = 'https://api.360.cn/v1/chat/completions';

    public function completions(string $id, string $model, string $content, array $img = [], $deepThink = false, $webSearch = false): void
    {
        $apiKey = Env::get('nami.apikey');
        if ($webSearch) {
            $this->completionsRequest(
                $id,
                $content,
                $model,
                $apiKey,
                function ($messages) use ($model) {
                    return json_encode(
                        [
                            'model'    => $model,
                            'messages' => $messages,
                            'stream'   => true,
                            'tools'    => [
                                 [
                                    'type'       => 'web_search',
                                    'web_search' => [
                                        'search_mode' => 'auto'
                                    ]
                                ]
                            ]
                        ]
                    );
                }
            );
        } else {
            $this->completionsRequest($id, $content, $model, $apiKey);
        }
    }
}

